//
//  PPAlertController.m
//  PPAlertView
//
//  Created by 王岩 on 16/7/6.
//  Copyright © 2016年 yanwang. All rights reserved.
//

#import "PPAlertController.h"

@implementation PPAlertController

+ (void)alertWithTitle:(NSString * __nullable)title alertMessage:(NSString * __nullable)message buttonTitles:(NSArray <NSString *> * __nullable)buttonTitles alertVC:(UIViewController * _Nonnull)alertVC selectButtonBlock:(PPAlertControllerBlock __nullable)block
{
    UIAlertController *alertC = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
    if (buttonTitles.count > 0)
    {
        for (NSInteger i = 0; i < buttonTitles.count; i ++)
        {
            UIAlertAction *act = [UIAlertAction actionWithTitle:buttonTitles[i] style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                if (block)
                {
                    block(i);
                }
            }];
            [alertC addAction:act];
        }
    }
    else
    {
        UIAlertAction *act = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            if (block)
            {
                block(0);
            }
        }];
        [alertC addAction:act];
    }
    
    [alertVC presentViewController:alertC animated:YES completion:nil];
}

@end
